﻿using System.Data;

namespace VirtualAccess
{
    public class SelectCommand : DmlCommand
    {
        private DataSource _dataSource;
        private IDbCommand _localCommand;
        private IDataReader _dataReader;

        public SelectCommand(IDataProvider dataProvider)
            : base(dataProvider)
        {
            this._localCommand = dataProvider.CreateLocalCommand();
            this._localCommand.CommandType = CommandType.Text;
        }

        public SelectCommand(IDataProvider dataProvider, DataSource dataSource)
            : base(dataProvider)
        {
            this.DataSource = dataSource;
        }

        public DataSource DataSource
        {
            get { return _dataSource; }
            set { _dataSource = value; }
        }

        public string CommandText
        {
            get { return _localCommand.CommandText; }
            set { _localCommand.CommandText = value; }
        }

        public IDataReader DataReader
        {
            get { return _dataReader; }
        }

        public override object Execute()
        {
            _dataReader = DataProvider.CreateDataReader(_localCommand.ExecuteReader());
            return _dataReader;
        }
    }
}
